
//% color="#9f32f1" iconWidth=50 iconHeight=40
namespace gravitytts {


    //% block="TTS begin [VER]" blockType="command"
    //% VER.shadow="dropdown" VER.options="VER"
    export function begin(parameter: any, block: any) {
        let ver = parameter.VER.code;
        Generator.addImport(`import sys\nsys.path.append("/root/mindplus/.lib/thirdExtension/liliang-gravitytts-thirdex")\nfrom dfrobot_speech_synthesis import *`);
        Generator.addInit(`ttsobject`,`gravity_sstts = DFRobot_SpeechSynthesis_I2C()`);
        Generator.addCode(`gravity_sstts.begin(gravity_sstts.${ver})`);
 
    }

    //% block="TTS speak [STR]" blockType="command"
    //% STR.shadow="string"  STR.defl="你好"   
    export function speak(parameter: any, block: any) {
        let str = parameter.STR.code;
        Generator.addCode(`gravity_sstts.speak(${str})`);
 
    }

    //% block="---"
    export function space1(){

    }  
    //% block="TTS set Voice[VOICE] Speed[SPEED] Tone[TONE] SoundType[SOUNDTYPE]" blockType="command"
    //% VOICE.shadow="range"  VOICE.params.min=0    VOICE.params.max=10    VOICE.defl=8
    //% SPEED.shadow="range"  SPEED.params.min=0    SPEED.params.max=10    SPEED.defl=5
    //% SOUNDTYPE.shadow="dropdown"  SOUNDTYPE.options="SOUNDTYPE"
    //% TONE.shadow="range"  TONE.params.min=0    TONE.params.max=10    TONE.defl=5
    export function setBase(parameter: any, block: any) {
        let voice = parameter.VOICE.code;
        let speed = parameter.SPEED.code;
        let type = parameter.SOUNDTYPE.code;
        let tone = parameter.TONE.code;
        Generator.addCode(`gravity_sstts.set_voice(${voice})`); 
        Generator.addCode(`gravity_sstts.set_speed(${speed})`);
        Generator.addCode(`gravity_sstts.set_sound_type(${type})`);
        Generator.addCode(`gravity_sstts.set_tone(${tone})`);
 
 
    }


    //% block="TTS setEnglishPron [PRON]" blockType="command"
    //% PRON.shadow="dropdown"  PRON.options="PRON"  
    export function setEnglishPron(parameter: any, block: any) {
        let pron = parameter.PRON.code;
        Generator.addCode(`gravity_sstts.set_english_pron(${pron})`);
 
    }

    //% block="TTS setNumberPron [NUMB]" blockType="command"
    //% NUMB.shadow="dropdown"  NUMB.options="NUMB"  
    export function setNumberPron(parameter: any, block: any) {
        let numb = parameter.NUMB.code;
        Generator.addCode(`gravity_sstts.set_digital_pron(${numb})`);
 
    }

}
